home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: joebelle@ix.netcom.com (Al Belle)
- Newsgroups: comp.lang.c
- Subject: Need help with sorting and building tree
- Date: Sat, 09 Mar 1996 06:03:22 GMT
- Organization: Netcom
- Message-ID: <4hpti1$d5t@ixnews2.ix.netcom.com>
- NNTP-Posting-Host: ix-ytn-oh1-19.ix.netcom.com
- X-NETCOM-Date: Fri Mar 08 10:16:33 AM PST 1996
- X-Newsreader: Forte Free Agent 1.0.82
-
-
- Here is my situation.
- I have an array of string that I must sort using the binary sort method and while I am sorting must recursivly
- put them into a binary tree. I have tried everything and am running out of time. My array is defined globally.
-
-
- void sort(nodetype *p,int high,int low)
- {
- int middle=0;
- while(low<=high)
- {
- middle=(low+high)/2;
- maketree(p,array[middle]);
- high=middle-1;
- }
- }
-
- void maketree(nodetype *p, char *x)
- {
- if (p==NULL)
- {
- p=(nodetype *)malloc(sizeof(nodetype));
- if(p!=NULL){
- p->info=x;
- p->left=p->right=NULL;}
- else
- printf("No memory\n");
- }
- else
- if (x < p->info) <-------------------------------------------------------This doesnt seem to work either????????
- maketree(p->left,x)
- else
- if (x> p->info)
- maketree(p->right,x)
- }
-
- Am I comparing the value to be inserted "(x<p->info)" right. I figured the compiler would use the intiger values if I
- tried to compare them.(Im using GCC) Only 5 items of my array are being put into the tree out of a possible 52
- (The 52 states!); I know my logic is wrong somewhere but cant seem to figure it out. If anyone could post a
- possible suggestion It would be great.
- TIA
- joebelle@ix.netcom.com
-
-
-
-